﻿/******************************************************************************
 * 【本类功能概述】                                 					      *
 *  版权所有（C）2017-20XX，米兔网络                                         *
 *  保留所有权利。                                                            *
 ******************************************************************************
 *  作者 : <hughjk>
 *  创建时间:2019年6月3日 18:58:38
 *  文件描述:简单存储一个Int值的缓存队列
 *****************************************************************************/

namespace StorageModels
{
    using System.Collections.Generic;

    public class StorageEasyInt : StorageModel
    {
        private Dictionary<StorageIntKey, int> EasyValue = new Dictionary<StorageIntKey, int>();
        private Dictionary<StorageIntKey, string> EasyKey = new Dictionary<StorageIntKey, string>();
        private List<StorageIntKey> PrepareEasyIntKey = new List<StorageIntKey>();

        public static StorageEasyInt Loads()
        {
            return StorageModelSys.Instance.GetModelData<StorageEasyInt>(StorageModelType.EasyInt);
        }

        public override void Load()
        {
            //var arr = Enum.GetValues(typeof(StorageIntKey));
            //for (int i = 0; i < arr.Length; i++)
            //{
            //    int ikey = (int)arr.GetValue(i);
            //    StorageIntKey tkey = (StorageIntKey)ikey;
            //    string key = string.Format("{0}_{1}", Key, ikey);//存档真实键
            //    int v = GameEntry.Setting.GetInt(key);//获取存档
            //
            //    EasyValue.Add(tkey, v);
            //    EasyKey.Add(tkey, key);
            //}
        }

        public void SetInt(StorageIntKey skey, int v)
        {
            EasyValue[skey] = v;
            PrepareEasyIntKey.Add(skey);
            Save();
        }

        public int GetInt(StorageIntKey skey)
        {
            return EasyValue[skey];
        }

        public override void Write()
        {
            base.Write();
            for (int i = 0; i < PrepareEasyIntKey.Count; i++)
            {
                StorageIntKey skey = PrepareEasyIntKey[i];
                string key = EasyKey[skey];
                int v = EasyValue[skey];
                //真实写存档
                //GameEntry.Setting.SetInt(key, v);
            }
            PrepareEasyIntKey.Clear();
        }
    }
}